﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GrewalCRM.Entities
{
  [Serializable]
  public abstract class  BaseEntitiesGrewalCRM
  {
    #region Members
    private int id;
    private bool isActive = true;
    private UserCRM lastModifiedUser = null;
    private DateTime? lastModifiedDateTime = null;
    private bool isChanged;
    private bool isMarkedDeleted = false;
    #endregion

    #region Constructors
		/// <summary>
		/// Create a new instance using the default constructor
		/// </summary>
    protected BaseEntitiesGrewalCRM()
		{
			isChanged = true;      
		}

    /// <summary> 
    /// Create a new object using the minimum required information (all not-null fields except 
    /// ID keys). 
    /// </summary> 
    protected BaseEntitiesGrewalCRM(UserCRM LastModifiedUser)
        : this()
    {
        lastModifiedUser = LastModifiedUser;        
        lastModifiedDateTime = null;
    }

    /// <summary> 
    /// Create a new object using the minimum required information (all not-null fields except 
    /// ID keys). 
    /// </summary> 
    protected BaseEntitiesGrewalCRM(bool isActive, UserCRM LastModifiedUser):this()
    {    
      lastModifiedUser = LastModifiedUser;
      this.isActive = isActive;
      lastModifiedDateTime = null;
    }

    /// <summary> 
    /// Create an object from an existing row of data. This will be used by Gentle to 
    /// construct objects from retrieved rows. 
    /// </summary>   
    protected BaseEntitiesGrewalCRM(int ID, bool IsActive, UserCRM LastModifiedUser, DateTime? LastModifiedDateTime)
      : this(IsActive, LastModifiedUser)
    {
      isChanged = false;
      id = ID;      
      lastModifiedDateTime = LastModifiedDateTime;
    }

    protected BaseEntitiesGrewalCRM(int ID, UserCRM LastModifiedUser, DateTime? LastModifiedDateTime)
        : this(LastModifiedUser)
    {
        isChanged = false;
        id = ID;
        lastModifiedDateTime = LastModifiedDateTime;
    }

  #endregion

    #region Public Properties
    /// <summary>
    /// Property relating to database column ID
    /// </summary>
    public int ID
    {
      get { return id; }
      set { isChanged |= id != value; id = value; }
    }

    /// <summary>
    /// Indicates whether the entity is active or not.
    /// </summary>
    public bool IsActive
    {
      get { return isActive; }
      set { isActive = value; }
    }

    /// <summary>
    /// Indicates whether the entity is changed and requires saving or not.
    /// </summary>
    public bool IsChanged
    {
      get { return isChanged; }
      protected set { isChanged = value; }
    }

    /// <summary>
    /// Indicates whether the entity is marked deleted and requires deleting or not.
    /// </summary>
    public bool IsMarkedDeleted
    {
      get { return isMarkedDeleted; }
      set { isMarkedDeleted = value; }
    }

    /// <summary>
    /// Property relating to database column LastModifiedUser
    /// </summary>    
    public UserCRM LastModifiedUser
    {
      get { return lastModifiedUser; }
      set { isChanged |= lastModifiedUser != value; lastModifiedUser = value; }
    }    

    /// <summary>
    /// Property relating to database column LastModifiedDateTime
    /// </summary>   
    public DateTime? LastModifiedDateTime
    {
      get { return lastModifiedDateTime; }
      set { isChanged |= lastModifiedDateTime != value; lastModifiedDateTime = value; }
    }   
    #endregion
    
  }
}
